﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Common
{
    public partial class AddVisitDialog : UserControl, IAddVisitDialog
    {
        #region IAddVisitDialog Members

        public object DataSource
        {
            get
            {
                return null;
            }
            set
            {
                buyerComboBox.DataSource = value;
            }
        }

        public object Current
        {
            get
            {
                return buyerComboBox.SelectedItem;
            }
        }

        public object SelectedBuyPoint
        {
            get
            {
                return buyPointComboBox.SelectedItem;
            }
        }

        public object BuyPoints
        {
            set
            {
                buyPointComboBox.DataSource = value;
            }
        }

        public string Adress
        {
            set
            {
                adressLabel.Text = value;
            }
        }



        public Dictionary<string, bool> SelectDays
        {
            get
            {
                Dictionary<string, bool> res = new Dictionary<string, bool>();
                res["Sunday"] = sundayCheckBox.Checked;
                res["Monday"] = mondayCheckBox.Checked;
                res["Tuesday"] = tuesdayCheckBox.Checked;
                res["Wednesday"] = wednesdayCheckBox.Checked;
                res["Thursday"] = thursdayCheckBox.Checked;
                res["Friday"] = fridayCheckBox.Checked;
                res["Saturday"] = saturdayCheckBox.Checked;
                return res;
            }
        }

        public event EventHandler<EventArgs> OK;

        public event EventHandler<EventArgs> Cancel;

        public event EventHandler<EventArgs> SelectBuyer;

        public event EventHandler<EventArgs> SelectBuyPoint;

        #endregion

        public AddVisitDialog()
        {
            DateTime start = DateTime.Now;
            InitializeComponent();
            new AddVisitDialogPresenter(this);
            buyerComboBox.DisplayMember = "NameBuyer";
            buyPointComboBox.DisplayMember = "NameBuyPoint";
            selectDayPanel.Visible = false;
            DateTime end = DateTime.Now;
            MessageBox.Show((end - start).ToString());
        }

        public AddVisitDialog(bool daySelect): this()
        {
            selectDayPanel.Visible = daySelect;
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            OK(this, null);
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            Cancel(null, null);
        }

        private void buyPointComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            SelectBuyPoint(null, null);
        }

        private void buyerComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            SelectBuyer(null, null);
        }
    }
}
